package edu.hubu.talentmanagementsystem.auth;

import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author moonlan
 * date 2021/2/9 下午1:35
 * TODO:实现AbstractAuthenticationProcessingFilter的过滤器只在Login的时候起作用
 */
@SuppressWarnings(value = "unused")
public class JwtTokenAuthorizationTokenFilter extends OncePerRequestFilter {

    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
        String token = request.getHeader("Authorization");
        JwtToken jwtToken = token != null ? new JwtToken(token): null;
        SecurityContextHolder.getContext().setAuthentication(jwtToken);
        chain.doFilter(request, response);
    }

}
